package com.quwan.manager.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.common.query.LambdaQueryWrapperX;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TAdmin;
import com.quwan.entity.TMemberReport;
import com.quwan.manager.controller.dto.AdminDto;
import com.quwan.manager.service.AdminService;
import com.quwan.mapper.TAdminMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author laozhang
 * @date 2021/9/25 11:54
 */
@Service
@RequiredArgsConstructor
public class AdminServiceImpl implements AdminService {

    private final TAdminMapper adminMapper;

    @Override
    public PageResult<AdminDto> getAdminListPage(int page, int size,Long id, String name,String beginTime,String endTime) {
       if(StringUtils.isNotBlank(endTime)) {
            endTime = endTime+" 23:59:59";
        }
        Page<AdminDto> adminPage = adminMapper.selectAdminDtoList(new Page<>(page, size),id,name,beginTime,endTime);
        PageResult<AdminDto> result = new PageResult<AdminDto>()
                .setCurrent(adminPage.getCurrent())
                .setPages(adminPage.getPages())
                .setSize(adminPage.getSize())
                .setTotal(adminPage.getTotal())
                .setRecords(adminPage.getRecords());
        return result;
    }

    @Override
    public List<AdminDto> getAdminList(Long id, String name,String beginTime,String endTime) {
        if(StringUtils.isNotBlank(endTime)) {
            endTime = endTime+" 23:59:59";
        }
        List<AdminDto> res = adminMapper.selectAdminDtoList(id,name,beginTime,endTime);
        return res;
    }

    @Override
    public boolean addAdmin(TAdmin admin) {
        return adminMapper.insert(admin) == 1;
    }

    @Override
    public boolean updateAdmin(TAdmin admin) {
        return adminMapper.updateById(admin) == 1;
    }

    @Override
    public TAdmin detailAdmin(Integer id) {
        return adminMapper.selectById(id);
    }

    @Override
    public boolean delAdmin(Integer id) {
        return adminMapper.deleteById(id) == 1;
    }

}
